﻿using YunQue.Core.Common.Enums;

namespace YunQue.Core.Common.QuartzManager
{
    /// <summary>
    /// job执行参数
    /// </summary>
    public class JobExecuteParam
    {
        /// <summary>
        /// 接口请求地址
        /// </summary>
        public string WebhookUrl { get; set; }
        /// <summary>
        /// 请求头
        /// </summary>
        public Dictionary<string, string> Headers { get; set; }
        /// <summary>
        /// 超时时间
        /// </summary>
        public TimeSpan? Timeout { get; set; }
        /// <summary>
        /// 请求方法
        /// </summary>
        public HttpMethodEnum HttpMethod { get; set; }
        /// <summary>
        /// 请求参数
        /// </summary>
        public Dictionary<string, object> Params { get; set; }
        /// <summary>
        /// 构建带参数的URL
        /// </summary>
        /// <returns></returns>
        public string BuildUrlWithParamString()
        {
            if (Params == null || Params.Count == 0)
            {
                return this.WebhookUrl;
            }
            var paramList = Params.Select(kv => $"{Uri.EscapeDataString(kv.Key)}={Uri.EscapeDataString(kv.Value?.ToString() ?? string.Empty)}");
            if(this.WebhookUrl.Contains("?"))
            {
                return this.WebhookUrl + "&" + string.Join("&", paramList);
            }
            return this.WebhookUrl + "?" + string.Join("&", paramList);
        }

    }
}
